package br.com.concurso.model;

import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.ServiceRegistryBuilder;
import org.hibernate.tool.hbm2ddl.SchemaExport;

import br.com.concurso.pojo.*;

public class Facade {

	private static SessionFactory factory;
	private static ServiceRegistry serviceRegistry; 
	
	public static void main(String[] args){
		try{
			Configuration configuration = new Configuration();
			configuration.configure();
			serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).build();
			
			
			configuration.addAnnotatedClass(Materia.class);
			new SchemaExport(configuration).create(true, true);
			
			factory = configuration.buildSessionFactory(serviceRegistry);
			
			
		}catch (Throwable ex) { 
			System.err.println("Failed to create sessionFactory object." + ex);
		throw new ExceptionInInitializerError(ex); 
		}
		
	}
}
